/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 *\author: starlove
 *************************************************************************/
#ifndef __CC_PYTHON_IMPORT_O_EXT_SCROLLVIEW_IMPL__
#define __CC_PYTHON_IMPORT_O_EXT_SCROLLVIEW_IMPL__

#include "python_object_ext_scrollview.h"
#include "python_object_texture2d.h"

NS_CCPY_BEGIN
	CCLAYER_OBJECT_WRAPPER_IMPL(CCScrollView, CPyScrollView)

	PYCLASS_INIT_AND_BASE(CPyScrollView, CPyLayer, "CCScrollView", "Python CCScrollView Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyScrollView)
		PYCLASS_ADD_METHOD_EX(CPyScrollView, setContentOffset				, METH_KEYWORDS|METH_VARARGS)
		PYCLASS_ADD_METHOD(CPyScrollView, getContentOffset)
		PYCLASS_ADD_METHOD(CPyScrollView, setContentOffsetInDuration)
		PYCLASS_ADD_METHOD_EX(CPyScrollView, setZoomScale					, METH_KEYWORDS|METH_VARARGS)
		PYCLASS_ADD_METHOD(CPyScrollView, getZoomScale)
		PYCLASS_ADD_METHOD(CPyScrollView, setZoomScaleInDuration)
		PYCLASS_ADD_METHOD(CPyScrollView, updateInset)
		PYCLASS_ADD_METHOD(CPyScrollView, isNodeVisible)
		PYCLASS_ADD_METHOD(CPyScrollView, pause)
		PYCLASS_ADD_METHOD(CPyScrollView, resume)
	PYCLASS_END_METHOD_DEF(CPyScrollView)
	PYCLASS_BEGIN_GETSET_DEF(CPyScrollView)
		PYCLASS_ADD_GET(CPyScrollView, minContainerOffset)
		PYCLASS_ADD_GET(CPyScrollView, maxContainerOffset)
		PYCLASS_ADD_GET(CPyScrollView, Dragging)
		PYCLASS_ADD_GET(CPyScrollView, TouchMoved)
		PYCLASS_ADD_GETSET(CPyScrollView, Bounceable)
		PYCLASS_ADD_GETSET(CPyScrollView, ViewSize)
		PYCLASS_ADD_GETSET(CPyScrollView, Container)
		PYCLASS_ADD_GETSET(CPyScrollView, Direction)
		PYCLASS_ADD_GETSET(CPyScrollView, Delegate)
		PYCLASS_ADD_GETSET(CPyScrollView, ClippingToBounds)
	PYCLASS_END_GETSET_DEF(CPyScrollView)
	PYCLASS_IMP_INTERFACE_NEW(CPyScrollView)

	int CPyScrollView::__init__(CPyScrollView *pySelf, PyObject *args, PyObject *kwds)
	{
		if( !args )
			return 0;
		static char* kwlist[] = {"size", "container", NULL};
		PyObject *py_size = NULL;
		PyObject *py_container = NULL;
		if (!PyArg_ParseTupleAndKeywords(args,kwds,"O|O", kwlist, &py_size, &py_container))
			return 0;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		if(!py_size || !PyObject_TypeCheck(py_size, CPyClassBase::GetTypeObject<CPySize>()))
			return 0;
		CPySize *size = (CPySize *)py_size;

		CCNode *p = NULL;
		if(py_container)
		{
			CPyCCObject *py_c = (CPyCCObject *)py_container;
			p = dynamic_cast<CCNode *>(py_c->getCCObject());
		}
		spr->initWithViewSize(size->getCCObject(), p);
		return 0;
	}

	void CPyScrollView::__del__(CPyScrollView *self)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(self->getCCObject());
		if(spr)
		{
			CWrapScrollViewDelegate *wrap = dynamic_cast<CWrapScrollViewDelegate *>(spr->getDelegate());
			if(wrap)
			{
				Py_SAFE_DECREF(wrap->getPyObject());
			}
		}
		self->ob_type->tp_free(self);
	}

	PYCLASS_METHOD_KW_IMPL(CPyScrollView, setContentOffset)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		static char* kwlist[] = {"offset", "animated", NULL};
		PyObject *py_offset = NULL;
		PyObject *py_animated = NULL;
		if (!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"O|O", kwlist, &py_offset, &py_animated))
			Py_RETURN_NONE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		if(!py_offset || !PyObject_TypeCheck(py_offset, CPyClassBase::GetTypeObject<CPyPoint>()))
			Py_RETURN_NONE;
		CPyPoint *offset = (CPyPoint *)py_offset;
		bool animated = py_animated == Py_True;

		spr->setContentOffset(offset->getCCObject(), animated);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, getContentOffset)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		CCPoint pt = spr->getContentOffset();
		return (PyObject *)CPyPoint::create(pt);
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, setContentOffsetInDuration)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		PyObject *py_offset = NULL;
		float dt = 0;
		if (!PyArg_ParseTuple(pyArgs,"Of", &py_offset, &dt))
			Py_RETURN_NONE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		if(!py_offset || !PyObject_TypeCheck(py_offset, CPyClassBase::GetTypeObject<CPyPoint>()))
			Py_RETURN_NONE;
		CPyPoint *offset = (CPyPoint *)py_offset;
		spr->setContentOffsetInDuration(offset->getCCObject(), dt);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_KW_IMPL(CPyScrollView, setZoomScale)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		static char* kwlist[] = {"s", "animated", NULL};
		float s = 0;
		PyObject *py_animated = NULL;
		if (!PyArg_ParseTupleAndKeywords(pyArgs,pyKW,"f|O", kwlist, &s, &py_animated))
			Py_RETURN_NONE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		if(py_animated)
		{
			bool animated = py_animated == Py_True;
			spr->setZoomScale(s, animated);
		}else
			spr->setZoomScale(s);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, getZoomScale)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		float s = spr->getZoomScale();
		return Py_BuildValue("f", s);
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, setZoomScaleInDuration)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		float s = 0;
		float dt = 0;
		if (!PyArg_ParseTuple(pyArgs,"ff", &s, &dt))
			Py_RETURN_NONE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		spr->setZoomScaleInDuration(s, dt);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, updateInset)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		spr->updateInset();
		Py_RETURN_NONE;
	}


	PYCLASS_METHOD_IMPL(CPyScrollView, isNodeVisible)
	{
		if( !pyArgs )
			Py_RETURN_FALSE;
		PyObject *py_node = NULL;
		if (!PyArg_ParseTuple(pyArgs,"O", &py_node))
			Py_RETURN_FALSE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_FALSE;
		CPyCCObject *pp = (CPyCCObject *)py_node;
		CCNode *p = dynamic_cast<CCNode *>(pp->getCCObject());
		if(!p)
			Py_RETURN_FALSE;
		bool b = spr->isNodeVisible(p);
		Py_RETURN_BOOL(b);
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, pause)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		PyObject *py_node = NULL;
		if (!PyArg_ParseTuple(pyArgs,"O", &py_node))
			Py_RETURN_NONE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		CPyCCObject *pp = (CPyCCObject *)py_node;
		CCObject *p = dynamic_cast<CCObject *>(pp->getCCObject());
		if(p)
			spr->pause(p);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyScrollView, resume)
	{
		if( !pyArgs )
			Py_RETURN_NONE;
		PyObject *py_node = NULL;
		if (!PyArg_ParseTuple(pyArgs,"O", &py_node))
			Py_RETURN_NONE;
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		CPyCCObject *pp = (CPyCCObject *)py_node;
		CCObject *p = dynamic_cast<CCObject *>(pp->getCCObject());
		if(p)
			spr->resume(p);
		Py_RETURN_NONE;
	}
	
	PYCLASS_GET_IMPL(CPyScrollView, minContainerOffset)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		return (PyObject *)CPyPoint::create(spr->minContainerOffset());
	}

	PYCLASS_GET_IMPL(CPyScrollView, maxContainerOffset)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		return (PyObject *)CPyPoint::create(spr->maxContainerOffset());
	}

	PYCLASS_GET_IMPL(CPyScrollView, Dragging)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		Py_RETURN_BOOL(spr->isDragging());
	}

	PYCLASS_GET_IMPL(CPyScrollView, TouchMoved)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		Py_RETURN_BOOL(spr->isTouchMoved());
	}
	
	PYCLASS_GET_IMPL(CPyScrollView, Bounceable)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		Py_RETURN_BOOL(spr->isBounceable());
	}

	PYCLASS_SET_IMPL(CPyScrollView, Bounceable)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		spr->setBounceable(pyValue == Py_True);
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyScrollView, ViewSize)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		return (PyObject *)CPySize::create(spr->getViewSize());
	}

	PYCLASS_SET_IMPL(CPyScrollView, ViewSize)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		CPySize *size = (CPySize *)pyValue;
		spr->setViewSize(size->getCCObject());
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScrollView, Container)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		IWrapper *wrap = dynamic_cast<IWrapper *>(spr->getContainer());
		if(wrap)
			return CPyCCObject::create_object(wrap->GetPythonType(), spr->getContainer());
		return (PyObject *)CPyCCObject::create<CPyNode>(spr->getContainer());
	}

	PYCLASS_SET_IMPL(CPyScrollView, Container)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		CPyCCObject *pp = (CPyCCObject *)pyValue;
		CCNode *p = dynamic_cast<CCNode *>(pp->getCCObject());
		if(!p)
			return 0;
		spr->setContainer(p);
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyScrollView, Direction)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		int s = static_cast<int>(spr->getDirection());
		return Py_BuildValue("i", s);
	}

	PYCLASS_SET_IMPL(CPyScrollView, Direction)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		CCScrollViewDirection d = static_cast<CCScrollViewDirection>(PyLong_AsLong(pyValue));
		spr->setDirection(d);
		return 0;
	}
	
	
	PYCLASS_GET_IMPL(CPyScrollView, ClippingToBounds)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		Py_RETURN_BOOL(spr->isClippingToBounds());
	}

	PYCLASS_SET_IMPL(CPyScrollView, ClippingToBounds)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		spr->setClippingToBounds(pyValue == Py_True);
		return 0;
	}

	PYCLASS_GET_IMPL(CPyScrollView, Delegate)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			Py_RETURN_NONE;
		CWrapScrollViewDelegate *wrap = dynamic_cast<CWrapScrollViewDelegate *>(spr->getDelegate());
		if(!wrap)
			Py_RETURN_NONE;
		return wrap->getPyObject();
	}

	PYCLASS_SET_IMPL(CPyScrollView, Delegate)
	{
		CCScrollView *spr = dynamic_cast<CCScrollView *>(pySelf->getCCObject());
		if(!spr)
			return 0;
		if(PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyScrollViewDelegate>()))
		{
			CWrapScrollViewDelegate *wrap = dynamic_cast<CWrapScrollViewDelegate *>(spr->getDelegate());
			if(wrap)
			{
				Py_SAFE_DECREF(wrap->getPyObject());
			}

			Py_XINCREF(pyValue);
			CPyScrollViewDelegate *pydel = (CPyScrollViewDelegate *)pyValue;
			spr->setDelegate(pydel->getCObject());
		}
		return 0;
	}
	
	PYCLASS_INIT_F(CPyScrollViewDelegate, "CCScrollViewDelegate", "Python CCScrollViewDelegate Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyScrollViewDelegate)
		PYCLASS_ADD_METHOD(CPyScrollViewDelegate, scrollViewDidScroll)
		PYCLASS_ADD_METHOD(CPyScrollViewDelegate, scrollViewDidZoom)
	PYCLASS_END_METHOD_DEF(CPyScrollViewDelegate)
	PYCLASS_BEGIN_GETSET_DEF(CPyScrollViewDelegate)
	PYCLASS_END_GETSET_DEF(CPyScrollViewDelegate)
	PYCLASS_IMP_INTERFACE_NODEL(CPyScrollViewDelegate)
	
	void CPyScrollViewDelegate::__del__(CPyScrollViewDelegate *self)
	{
		delete self->getCObject();
		self->ob_type->tp_free(self);
	}

	PYCLASS_METHOD_IMPL(CPyScrollViewDelegate, scrollViewDidScroll)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyScrollViewDelegate, scrollViewDidZoom)
	{
		Py_RETURN_NONE;
	}
	
	CCNODE_OBJECT_WRAPPER_IMPL(CCTableViewCell, CPyTableViewCell)

	PYCLASS_INIT_AND_BASE(CPyTableViewCell, CPyNode, "CCTableViewCell", "Python CCTableViewCell Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyTableViewCell)
		PYCLASS_ADD_METHOD(CPyTableViewCell, reset)
	PYCLASS_END_METHOD_DEF(CPyTableViewCell)
	PYCLASS_BEGIN_GETSET_DEF(CPyTableViewCell)
		PYCLASS_ADD_GETSET(CPyTableViewCell, ObjectID)
		PYCLASS_ADD_GETSET(CPyTableViewCell, Idx)
	PYCLASS_END_GETSET_DEF(CPyTableViewCell)
	PYCLASS_IMP_INTERFACE(CPyTableViewCell)
	
	PYCLASS_METHOD_IMPL(CPyTableViewCell, reset)
	{
		CCTableViewCell *cell = dynamic_cast<CCTableViewCell *>(pySelf->getCCObject());
		if(cell)
			cell->reset();
		Py_RETURN_NONE;
	}
		
	PYCLASS_GET_IMPL(CPyTableViewCell, ObjectID)
	{
		CCTableViewCell *cell = dynamic_cast<CCTableViewCell *>(pySelf->getCCObject());
		if(cell)
			return Py_BuildValue("I", cell->getObjectID());
		Py_RETURN_NONE;
	}

	PYCLASS_SET_IMPL(CPyTableViewCell, ObjectID)
	{
		CCTableViewCell *cell = dynamic_cast<CCTableViewCell *>(pySelf->getCCObject());
		if(cell)
			cell->setObjectID(PyLong_AsUnsignedLong(pyValue));
		return 0;
	}
		
	PYCLASS_GET_IMPL(CPyTableViewCell, Idx)
	{
		CCTableViewCell *cell = dynamic_cast<CCTableViewCell *>(pySelf->getCCObject());
		if(cell)
			return Py_BuildValue("I", cell->getIdx());
		Py_RETURN_NONE;
	}

	PYCLASS_SET_IMPL(CPyTableViewCell, Idx)
	{
		CCTableViewCell *cell = dynamic_cast<CCTableViewCell *>(pySelf->getCCObject());
		if(cell)
			cell->setIdx(PyLong_AsUnsignedLong(pyValue));
		return 0;
	}
	
	CCLAYER_OBJECT_WRAPPER_IMPL(CCTableView, CPyTableView)

	PYCLASS_INIT_AND_BASE_2(CPyTableView, CPyScrollView, CPyScrollViewDelegate, "CCTableView", "Python CCTableView Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyTableView)
		PYCLASS_ADD_METHOD(CPyTableView, updateCellAtIndex)
		PYCLASS_ADD_METHOD(CPyTableView, insertCellAtIndex)
		PYCLASS_ADD_METHOD(CPyTableView, removeCellAtIndex)
		PYCLASS_ADD_METHOD(CPyTableView, reloadData)
		PYCLASS_ADD_METHOD(CPyTableView, dequeueCell)
		PYCLASS_ADD_METHOD(CPyTableView, cellAtIndex)
	PYCLASS_END_METHOD_DEF(CPyTableView)
	PYCLASS_BEGIN_GETSET_DEF(CPyTableView)
		PYCLASS_ADD_GETSET(CPyTableView, DataSource)
		PYCLASS_ADD_GETSET(CPyTableView, Delegate)
		PYCLASS_ADD_GETSET(CPyTableView, VerticalFillOrder)
	PYCLASS_END_GETSET_DEF(CPyTableView)
	PYCLASS_IMP_INTERFACE_NEW(CPyTableView)

	int CPyTableView::__init__(CPyTableView *pySelf, PyObject *args, PyObject *kwds)
	{
		if( !args )
			return 0;
		static char* kwlist[] = {"dataSource", "size", "container", NULL};
		PyObject *py_dataSource = NULL;
		PyObject *py_size = NULL;
		PyObject *py_container = NULL;
		if (!PyArg_ParseTupleAndKeywords(args,kwds,"OO|O", kwlist, &py_dataSource, &py_size, &py_container))
			return 0;

		if(!py_dataSource || !PyObject_TypeCheck(py_dataSource, CPyClassBase::GetTypeObject<CPyTableViewDataSource>()))
			return 0;
		if(!py_size || !PyObject_TypeCheck(py_size, CPyClassBase::GetTypeObject<CPySize>()))
			return 0;
		CPyTableViewDataSource *dataSource = (CPyTableViewDataSource *)py_dataSource;
		CPySize *size = (CPySize *)py_size;

		CCNode *p = NULL;
		if(py_container)
		{
			CPyCCObject *py_c = (CPyCCObject *)py_container;
			p = dynamic_cast<CCNode *>(py_c->getCCObject());
		}
		
		CCTableView *spr = CCTableView::create(dataSource->getCObject(), size->getCCObject(), p);
		pySelf->setCCObject(spr);
		return 0;
	}

	void CPyTableView::__del__(CPyTableView *self)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(self->getCCObject());
		if(view)
		{
			CWrapTableViewDelegate *wrap = dynamic_cast<CWrapTableViewDelegate *>(view->getDelegate());
			if(wrap)
			{
				Py_SAFE_DECREF(wrap->getPyObject());
			}
			CWrapTableViewDataSource *ds = dynamic_cast<CWrapTableViewDataSource *>(view->getDataSource());
			if(ds)
			{
				Py_SAFE_DECREF(ds->getPyObject());
			}
		}
		self->ob_type->tp_free(self);
	}

	PYCLASS_METHOD_IMPL(CPyTableView, updateCellAtIndex)
	{
		unsigned int idx = 0;
		if (!PyArg_ParseTuple(pyArgs,"I", &idx))
			Py_RETURN_NONE;
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		if(view)
			view->updateCellAtIndex(idx);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyTableView, insertCellAtIndex)
	{
		unsigned int idx = 0;
		if (!PyArg_ParseTuple(pyArgs,"I", &idx))
			Py_RETURN_NONE;
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		if(view)
			view->insertCellAtIndex(idx);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyTableView, removeCellAtIndex)
	{
		unsigned int idx = 0;
		if (!PyArg_ParseTuple(pyArgs,"I", &idx))
			Py_RETURN_NONE;
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		if(view)
			view->removeCellAtIndex(idx);
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableView, reloadData)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		if(view)
			view->reloadData();
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyTableView, dequeueCell)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		CCTableViewCell *cell = NULL;
		if(view)
			if(cell = view->dequeueCell())
				return (PyObject *)CPyCCObject::create<CPyTableViewCell>(cell);
		Py_RETURN_NONE;
	}

	PYCLASS_METHOD_IMPL(CPyTableView, cellAtIndex)
	{
		unsigned int idx = 0;
		if (!PyArg_ParseTuple(pyArgs,"I", &idx))
			Py_RETURN_NONE;
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		CCTableViewCell *cell = NULL;
		if(view)
			if(cell = view->cellAtIndex(idx))
				return (PyObject *)CPyCCObject::create<CPyTableViewCell>(cell);
		Py_RETURN_NONE;
	}
	
	PYCLASS_GET_IMPL(CPyTableView, DataSource)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		CWrapTableViewDataSource *ds = NULL;
		if(view)
			if(ds = dynamic_cast<CWrapTableViewDataSource *>(view->getDataSource()))
				return ds->getPyObject();
		Py_RETURN_NONE;
	}
	PYCLASS_SET_IMPL(CPyTableView, DataSource)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyTableViewDataSource>() ))
			return 0;
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		CCTableViewDataSource *ds = ((CPyTableViewDataSource *)pyValue)->getCObject();
		if(view)
		{
			if(view->getDataSource())
			{
				CWrapTableViewDataSource *ods = dynamic_cast<CWrapTableViewDataSource *>(view->getDataSource());
				if(ods)
					Py_SAFE_DECREF(ods->getPyObject());
			}
			view->setDataSource(ds);
			Py_XINCREF(pyValue);
		}
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyTableView, Delegate)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		CWrapTableViewDelegate *dg = NULL;
		if(view)
			if(dg = dynamic_cast<CWrapTableViewDelegate *>(view->getDelegate()))
				return dg->getPyObject();
		Py_RETURN_NONE;
	}
	PYCLASS_SET_IMPL(CPyTableView, Delegate)
	{
		if(!PyObject_TypeCheck(pyValue, CPyClassBase::GetTypeObject<CPyTableViewDelegate>() ))
			return 0;
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		CCTableViewDelegate *dg = ((CPyTableViewDelegate *)pyValue)->getCObject();
		if(view)
		{
			if(view->getDelegate())
			{
				CWrapTableViewDelegate *odg = dynamic_cast<CWrapTableViewDelegate *>(view->getDelegate());
				if(odg)
					Py_SAFE_DECREF(odg->getPyObject());
			}
			view->setDelegate(dg);
			Py_XINCREF(pyValue);
		}
		return 0;
	}
	
	PYCLASS_GET_IMPL(CPyTableView, VerticalFillOrder)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		if(view)
			return Py_BuildValue("i", static_cast<int>(view->getVerticalFillOrder()));
		Py_RETURN_NONE;
	}
	PYCLASS_SET_IMPL(CPyTableView, VerticalFillOrder)
	{
		CCTableView *view = dynamic_cast<CCTableView *>(pySelf->getCCObject());
		if(view)
			view->setVerticalFillOrder(static_cast<CCTableViewVerticalFillOrder>(PyLong_AsLong(pyValue)));
		return 0;
	}

	
	PYCLASS_INIT_AND_BASE(CPyTableViewDelegate, CPyScrollViewDelegate, "CCTableViewDelegate", "Python CCTableViewDelegate Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyTableViewDelegate)
		PYCLASS_ADD_METHOD(CPyTableViewDelegate, tableCellTouched)
		PYCLASS_ADD_METHOD(CPyTableViewDelegate, tableCellHighlight)
		PYCLASS_ADD_METHOD(CPyTableViewDelegate, tableCellUnhighlight)
		PYCLASS_ADD_METHOD(CPyTableViewDelegate, tableCellWillRecycle)
	PYCLASS_END_METHOD_DEF(CPyTableViewDelegate)
	PYCLASS_BEGIN_GETSET_DEF(CPyTableViewDelegate)
	PYCLASS_END_GETSET_DEF(CPyTableViewDelegate)
	PYCLASS_IMP_INTERFACE_NODEL(CPyTableViewDelegate)
	
	void CPyTableViewDelegate::__del__(CPyTableViewDelegate *self)
	{
		delete self->getCObject();
		self->ob_type->tp_free(self);
	}

	PYCLASS_METHOD_IMPL(CPyTableViewDelegate, tableCellTouched)
	{
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableViewDelegate, tableCellHighlight)
	{
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableViewDelegate, tableCellUnhighlight)
	{
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableViewDelegate, tableCellWillRecycle)
	{
		Py_RETURN_NONE;
	}

	PYCLASS_INIT_F(CPyTableViewDataSource, "CCTableViewDataSource", "Python CCTableViewDataSource Object");
	PYCLASS_BEGIN_METHOD_DEF(CPyTableViewDataSource)
		PYCLASS_ADD_METHOD(CPyTableViewDataSource, tableCellSizeForIndex)
		PYCLASS_ADD_METHOD(CPyTableViewDataSource, cellSizeForTable)
		PYCLASS_ADD_METHOD(CPyTableViewDataSource, tableCellAtIndex)
		PYCLASS_ADD_METHOD(CPyTableViewDataSource, numberOfCellsInTableView)
	PYCLASS_END_METHOD_DEF(CPyTableViewDataSource)
	PYCLASS_BEGIN_GETSET_DEF(CPyTableViewDataSource)
	PYCLASS_END_GETSET_DEF(CPyTableViewDataSource)
	PYCLASS_IMP_INTERFACE_NODEL(CPyTableViewDataSource)
	
	void CPyTableViewDataSource::__del__(CPyTableViewDataSource *self)
	{
		delete self->getCObject();
		self->ob_type->tp_free(self);
	}

	PYCLASS_METHOD_IMPL(CPyTableViewDataSource, tableCellSizeForIndex)
	{
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableViewDataSource, cellSizeForTable)
	{
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableViewDataSource, tableCellAtIndex)
	{
		Py_RETURN_NONE;
	}
	PYCLASS_METHOD_IMPL(CPyTableViewDataSource, numberOfCellsInTableView)
	{
		Py_RETURN_NONE;
	}
NS_CCPY_END

#endif